/*eoOlaWkWY8h6ycBLK7AzoJfQ3GhcT0tQx/veNYmO0VBETNXtBbYPIklT6l0w8krO*/
import React, { Component } from 'react';
import constant from '../../constants';
import { afterEvent } from '../events';
import { detailAreaBeforeEvent } from './event';
import ampub from 'ampub';

const { utils } = ampub;
const { msgUtils, multiLangUtils } = utils;
const { showMessage } = msgUtils;
const { getMultiLangByID } = multiLangUtils;
export default class DetailList extends Component {

    constructor(props) {
        super(props);
    }

    render() {
        const { createCardTable } = this.props.cardTable;
        const { that } = this.props;
        return (
            <div className="nc-single-table">
                {createCardTable(constant.AREA.STEP.DETAIL_LIST, {
                    onAfterEvent: afterEvent.bind(this, that),
                    onBeforeEvent: detailAreaBeforeEvent.bind(this),
                    showIndex: true,
                    hideModelSave: true,
                    hideAdd: false,
                    adaptionHeight: true,
                    hideDel: false,
                    modelAddRow: (props, moduleId, moduleIndex) => {
                        // 设置新增行的值
                        props.cardTable.setValByKeyAndIndex(moduleId, moduleIndex + 1, 'check_result', {
                            display: getMultiLangByID(constant.CHECK_RESULT.PROFIT.display),
                            value: constant.CHECK_RESULT.PROFIT.value
                        });
                        props.cardTable.setValByKeyAndIndex(moduleId, moduleIndex + 1, 'card_num_after', { display: '1', value: '1' });
                        props.cardTable.setValByKeyAndIndex(moduleId, moduleIndex + 1, 'pk_inventory', {
                            display: that.state.pk_inventory,
                            value: that.state.pk_inventory
                        });
                        // 新增行类别名称可以编辑
                        setTimeout(() => {
                            props.cardTable.setEditableByIndex(moduleId, moduleIndex + 1, 'asset_name', true);
                            props.cardTable.setEditableByIndex(moduleId, moduleIndex + 1, 'pk_category', true);
                        }, 0);
                    },
                    modelDelRowBefore: (props, moduleId, modelIndex, record) => {
                        if (record.values.check_result.value == 1) {
                            return true;
                        } else {
                            showMessage.call(this, props, { color: 'warning', content: '非盘盈资产不能删除！' });
                            return false;
                        }
                    },
                })}
            </div>
        );
    }

}

/*eoOlaWkWY8h6ycBLK7AzoJfQ3GhcT0tQx/veNYmO0VBETNXtBbYPIklT6l0w8krO*/